<?php
    include '../../../controlador/php/conexion/Conexion.php';
    $con = new Conexion();
    
    $usuoid = $_REQUEST['oidusu'];
    
    $bentrada = "select count(*)as resp,soli.dnsestado,case when obs.hisobs is null then '' else obs.hisobs end as hisobs,
                       case when obs.dns is null then '' else obs.dns end as dns,obs.hisestadotc
                 from dnsolicitud as soli left outer join dnhistorial on soli.dnsoid = dnhistorial.dnsolicitud
                 outer apply(select his.hisobs,his.dnsolicitud as dns,his.hisestadotc
                                    from dnhistorial as his
                                    where his.hisestado = 8 and his.dnsolicitud = soli.dnsoid)as obs
                 where soli.usu_oid = ".$usuoid." and (dnsestado = 4 or dnsestado = 5 or dnsestado = 8)
                 group by soli.dnsestado,obs.hisobs,obs.dns,obs.hisestadotc";
    $res = $con->query($bentrada);
    
    
    while ($respu = mssql_fetch_array($res)){
        $respuesta[] = array_map(utf8_encode,$respu);
    }
    
    $con->cerrarConexion();
    print_r(json_encode($respuesta))
?>
